<template>
  <div class="photolist-container">
    <!-- 滑动区域 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <!--  data-wid="tab-top-subpage-1.html" -->
          <!-- mui的组件可以用@tap代替click -->
          <a
            :class="['mui-control-item', item.id==0 ? 'mui-active':'']"
            href="#item1mobile"
            v-for="item in dataList"
            :key="item.id"
            @click="getPhotoList(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>
    <!-- 图片区域 -->
    <ul>
      <!-- 注意制定渲染成li即可 -->
      <!-- 通过路由传递id,to前要加v-bind -->
      <router-link :to="'/home/photoinfo/'+ item.id" v-for="item in list" :key="item.id" tag="li">
        <img v-lazy="item.img_url" />
        <div class="info">
          <div class="info-title">{{item.title}}</div>
          <div class="info-body">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../src/lib/mui/js/mui.min.js";
// window.addEventListener("touchmove", func, { passive: false });
import { Toast } from "mint-ui";

// window.addEventListener("touchmove", e => e.preventDefault());
export default {
  data() {
    return {
      dataList: [],
      list: []
    };
  },
  created() {
    this.getAllCategory();
    this.getPhotoList(0);
  },
  mounted() {
    //在mounted初始化滚动条
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    //   获取页面的title和id，渲染header
    getAllCategory() {
      this.$http.get("getimgcategory").then(function(result) {
        if (result.data.status == 0) {
          result.body.message.unshift({ title: "全部", id: 0 });
          this.dataList = result.body.message;
          //   console.log(result);
        } else {
          Toast("加载失败");
        }
      });
    },
    getPhotoList(cateid) {
      this.$http.get("getimages/" + cateid).then(function(result) {
        if (result.data.status == 0) {
          this.list = result.body.message;
          console.log(result);
        }
      });
    }
  }
};
</script>
<style lang="scss">
/* 防止谷歌浏览器报错 无法被动侦听事件preventDefault， */

.photolist-container {
  touch-action: pan-y;
  ul {
    padding: 10px;
    margin: 0;
    padding-bottom: 0;
    // background-color: #fff;
    li {
      position: relative;
      list-style: none;
      box-shadow: 10px 10px rgba(0, 0, 0, 0.1);
      img {
        width: 100%;
        height: 300px;
        margin: auto;
      }
      .info {
        position: absolute;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.3);
        color: white;
        .info-title {
          font-size: 14px;
        }
        .info-body {
          font-size: 13px;
        }
      }
    }
  }
}
</style>